<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/21/0021
 * Time: 15:30
 */

namespace App\Http\Controllers\Api\Admin;


use App\Http\Controllers\Api\Controller;
use App\Http\Requests\Api\SaidanRequest;
use App\Models\Good;
use App\Models\Saidan;
use App\Transformers\GoodsinfoTransformer;
use App\Transformers\SaidanTransformer;
use App\Transformers\UsersTransformer;
use Illuminate\Http\Request;


class SaidanController extends Controller
{
    public function index(Saidan $saidan,Request $request){
        $params = $request->all();
        $query = $saidan->query();
        if (!empty($params['good_name'])){
            $query->where('good_name'.'like','%' .$params['good_name'] . '%');
        }

        $saidans =  $query->paginate(20);
        /*foreach ($goods as $good){
            dd($good->user);
        }*/
        return $this->response->paginator($saidans,new SaidanTransformer());
    }


    public function destory(Saidan $saidan ){
        // 权限

        $saidan->delete();

        return $this->response->noContent();
    }

    public function update(Saidan $saidan,SaidanRequest $request){

        $saidan->update(['is_pre'=>1]);
        return $this->response->created();
    }
}